import { Controller, Get, Query, Request } from '@nestjs/common';
import { ApiOperation, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger';
import { SearchService } from './search.service';
import { SearchParamsDto, SortOrder } from './dto/search-params.dto';
import { Public } from 'src/common/decorators/public';

@ApiTags('搜索')
@Controller('search')
export class SearchController {
  constructor(private readonly searchService: SearchService) {}
  
  /**
   * 搜索视频
   */
  @Get('videos')
  @Public()
  @ApiOperation({ summary: '搜索视频' })
  @ApiQuery({ name: 'keyword', description: '搜索关键词', required: true })
  @ApiQuery({ name: 'page', description: '页码', required: false, type: Number })
  @ApiQuery({ name: 'limit', description: '每页数量', required: false, type: Number })
  @ApiQuery({ 
    name: 'sort', 
    description: '排序方式', 
    required: false, 
    enum: SortOrder 
  })
  @ApiResponse({ status: 200, description: '搜索结果' })
  async searchVideos(@Query() params: SearchParamsDto, @Request() req) {
    const currentUserId = req.user?.id;
    return this.searchService.searchVideos(params, currentUserId);
  }

  /**
   * 搜索用户
   */
  @Get('users')
  @Public()
  @ApiOperation({ summary: '搜索用户' })
  @ApiQuery({ name: 'keyword', description: '搜索关键词', required: true })
  @ApiQuery({ name: 'page', description: '页码', required: false, type: Number })
  @ApiQuery({ name: 'limit', description: '每页数量', required: false, type: Number })
  @ApiQuery({ 
    name: 'sort', 
    description: '排序方式', 
    required: false, 
    enum: SortOrder 
  })
  @ApiResponse({ status: 200, description: '搜索结果' })
  async searchUsers(@Query() params: SearchParamsDto, @Request() req) {
    const currentUserId = req.user?.id;
    return this.searchService.searchUsers(params, currentUserId);
  }
}